package fr.afcepf.ai85.gepeto.service;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import fr.afcepf.ai85.ent.Connexion;
import fr.afcepf.ai85.ent.Eleve;
import fr.afcepf.ai85.hibernate.util.HibernateUtil;

public class ServiceConnexion {
	
	public static Connexion rechercherConnexionById(String log, String md) {
		
		Connexion con=null;

		Session session = HibernateUtil.currentSession();
		Transaction tx = session.beginTransaction();
		
		
		Query hql3 = session.createQuery("FROM Connexion cn WHERE cn.login like :log AND cn.motDePasse like :mdp");
		hql3.setString("log", log);
		hql3.setString("mdp", md);
		List<Connexion> liste= hql3.list();

		if (liste!=null){
			con=liste.get(0);
			
			System.out.println("ID de la connexion" + con.getIdConnexion());
		}
		HibernateUtil.closeSession();


		return con;
	}
	
	public static void main(String[] args) {
		System.out.println(rechercherConnexionById("CORSICA","Alexis"));
	}
}
